package com.cskaoyan.controller.admincontroller;

import com.cskaoyan.bean.po.MarketKeyword;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.adminservice.KeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author 楚夏三分
 * @datetime 2022/12/29 17:24
 * @description: TODO:
 */
@RestController
@RequestMapping("admin/keyword")
public class KeywordController {
    @Autowired
    KeywordService keywordService;

    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info, String url,String keyword){
        CommonData<MarketKeyword> data = keywordService.list(info,url,keyword);
        return BaseRespVo.ok(data);
    }

    /**
     * TODO: 新增关键字
     * @param map 关键字
     * @return
     */
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Map map){
        Boolean isDefault = (Boolean) map.get("isDefault");
        Boolean isHot = (Boolean) map.get("isHot");
        String keyword = (String)map.get("keyword");
        String url = (String)map.get("url");
        MarketKeyword marketKeyword = keywordService.create(isDefault,isHot,keyword,url);
        return BaseRespVo.ok(marketKeyword);
    }


    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketKeyword marketKeyword){
        MarketKeyword marketKeyword1 = keywordService.update(marketKeyword);
        return BaseRespVo.ok(marketKeyword1);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map){
        Integer id = (Integer) map.get("id");
        keywordService.delete(id);
        return BaseRespVo.ok();
    }
}
